package com.xzjt.utils;

import lombok.Data;

/**
 * @ClassName: R
 * @Author: yuandong
 * @Date 2021/10/9 8:46
 */
@Data
public class R<T> {

    private String code;
    private String msg;
    private T data;

    public R() {}


    public R(T data) {
        this.data = data;
    }


    public static R ok() {
        R r = new R<>();
        r.setCode("0");
        r.setMsg("成功");
        return r;
    }


    public static <T> R<T>  ok(T data) {
        R<T> r = new R<>(data);
        r.setCode("0");
        r.setMsg("成功");
        return r;
    }

    public static R error(String code, String msg) {
        R r = new R();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }


    /**
     * 服务器发生异常
     *
     * @return
     */
    public static R exception() {
        R r = new R();
        r.setCode("500");
        r.setMsg("服务器发生异常");
        return r;
    }


    /**
     * token 过期失效
     *
     * @return
     */
    public static R tokenExpired() {
        R r = new R();
        r.setCode("903");
        r.setMsg("token已经过期失效");
        return r;
    }



    /**
     * 请求参数异常
     *
     * @return
     */
    public static R paramsException() {
        R r = new R();
        r.setCode("907");
        r.setMsg("请求参数异常");
        return r;
    }

    /**
     * 验证码异常
     *
     * @return
     */
    public static R verifyCodeException() {
        R r = new R();
        r.setCode("908");
        r.setMsg("验证码错误");
        return r;
    }


    /**
     * 未找到相关资源
     *
     * @return
     */
    public static R notFound() {
        R r = new R();
        r.setCode("998");
        r.setMsg("未找到相关资源");
        return r;
    }




}
